//
//  FYTabbarController.m
//  MockProject
//
//  Created by FanYu on 8/20/16.
//  Copyright © 2016 niuzhaowang. All rights reserved.
//

#import "YXTabbarController.h"
#import "YXNavigationController.h"
#import "YXSettingViewController.h"
#import "YXTaskListViewController.h"
#import "Config.h"

@interface YXTabbarController ()

@end

@implementation YXTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupViewControllers];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)setupViewControllers {
    YXSettingViewController *settingVC = [[YXSettingViewController alloc] init];
    YXNavigationController *settingNavi = [[YXNavigationController alloc] initWithRootViewController:settingVC];
    
    YXTaskListViewController *taskListVC = [[YXTaskListViewController alloc] init];
    YXNavigationController *taskListNavi = [[YXNavigationController alloc] initWithRootViewController:taskListVC];
    
    self.tabBar.barTintColor = [UIColor whiteColor];
    
    [self setViewControllers:@[taskListNavi, settingNavi]];
    
    [self setTabBarForController:self];
}


- (void)setTabBarForController:(UITabBarController *)tabBarController {
    NSArray *tabBarItemUnselectedImages = @[@"任务icon正常状态", @"设置icon正常状态"];
    NSArray *taBarItemSelectedImages = @[@"任务icon当前选择状态", @"设置icon当前选择状态"];
    NSArray *titleNames = @[@"任务列表", @"设置"];
    
    NSInteger index = 0;
    
    for (UITabBarItem *item in [[tabBarController tabBar] items]) {
        //set icon
        UIImage *selectedimage = [[UIImage imageNamed:taBarItemSelectedImages[index]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        UIImage *unselectedimage = [[UIImage imageNamed:tabBarItemUnselectedImages[index]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [item setImage:unselectedimage];
        [item setSelectedImage:selectedimage];
        
        //设置tabbar的字体的大小和颜色(点击与未点击状态)
        [item setTitle:titleNames[index]];
        [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11], NSForegroundColorAttributeName:[UIColor colorWithHexString:@"ff4600"]} forState:UIControlStateSelected];
        [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11], NSForegroundColorAttributeName:[UIColor colorWithHexString:@"5e5e5e"]} forState:UIControlStateNormal];
        index++;
    }
    
    // title position
    //[tabBarController.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, 0)];
    
    // icon
    //[tabBarController.tabBarItem setImageInsets:UIEdgeInsetsMake(6, 0, -6, 0)];
    
    // separator line view
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * 0.5, 49 * 0.5 - 10, 0.5, 20)];
    lineView.backgroundColor = [UIColor colorWithHexString:@"e2e2e4"];
    [tabBarController.tabBar addSubview:lineView];
    
    // hairline view
//    [tabBarController.tabBar setShadowImage:[[UIImage alloc] init]];
//    [tabBarController.tabBar setBackgroundImage:[[UIImage alloc] init]];
//    [tabBarController.tabBar setBackgroundColor:[UIColor colorWithHexString:@"fcfcfc"]];
//    
//    UIView *hairLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.5)];
//    hairLineView.backgroundColor = [UIColor blackColor];
//    hairLineView.alpha = 0.2;
//    [tabBarController.tabBar addSubview:hairLineView];
}



@end
